home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / DOCS / AMOSDOC.LHA / AmosHyperBook.dms / in.adf / Manual / ALLIANCE-9 / ALLIANCE-9
Encoding:
Text File  |  1992-03-20  |  7.2 KB  |  256 lines

  1.  
  2. 9:MATHS FUNCTIONS
  3.  
  4. AMOS Basic includes a wide variety of the more commonly needed
  5. mathematical functions. To conserve memory, AMOS uses the standard
  6. Amiga library routines. The appropriate libraries will be loaded
  7. automatically from your workbench disc the first time you call one of
  8. these functions in a particular session. You should therefore ensure
  9. that the current disc contains the file MATHTRANS.LIBRARY in the LIBS
  10. folder.
  11.  
  12. Trigonometric functions
  13. The trigonometric functions provide you with a useful array of
  14. mathematical tools. These can be used for a variety of purposes, from
  15. education to the creation of complex musical wabeforms.
  16.  
  17.                          DEGREE (use degrees)
  18.  
  19. DEGREE
  20.  
  21. Generally all angles are specified in radians. Since radians are rather
  22. difficult to work with, it's possible to instruct AMOS to accept angles
  23. in degrees. Once you've activated this feature any subsequent calls to
  24. the trig functions will expect you to use degrees.
  25.  
  26.                       RADIAN (use radian measure)
  27.  
  28. RADIAN
  29.  
  30. THe RADIAN directive informs AMOS that all future angles are to be
  31. entered using radians - this is the default.
  32.  
  33.                          =PI# (a constant PI)
  34.  
  35. a#=PI#
  36.  
  37. This function returns the number called PI which represents the result
  38. of the division of the diameter of a circle by the circumference. PI is
  39. used by most of the trigonometric functions to calculate angels. Note
  40. that a # character is part of the token name! This is to avoid clashes
  41. with your own variable names.
  42.  
  43.                               =SIN (sine)
  44.  
  45. s#=SIN(a)
  46. s#=SIN(a#)
  47.  
  48. The SIN functions calculates the sine of the angle in n. Note that the
  49. function always returns a floating point number.
  50.  
  51.                              =COS (cosine)
  52. c#=COS(a[#])
  53.  
  54. The cosine function computes the cosine of an angle.
  55.  
  56.                             =TAN (tangent)
  57.  
  58. t#=TAN(a[#])
  59.  
  60. TAN generates the tangent of an angle.
  61.  
  62.                             =ACOS (arc cos)
  63.  
  64. c#=ACOS(n#)
  65.  
  66. The ACOS function takes a number between -1 and +1 and calculates the
  67. angle which would be needed to generate this value with COS.
  68.  
  69. Note, we haven't provided you with ASIN, because it's not really
  70. needed. It can be readily computed using the formula:
  71.  
  72. ASIN(X)=90-ACOS(X) : Rem Measured in degrees.
  73. ASIN(X)=1.5708-ACOS(X) : Rem using radians
  74.  
  75.                           =ATAN (arc tangent)
  76.  
  77. t#=ATAN(n#)
  78.  
  79. ATAN returns the arctan of a number.
  80.  
  81.                         =HSIN (hyperbolic sine)
  82.  
  83. s#=HSIN(a[#])
  84.  
  85. HSIN computes the hyperbolic sine of angle a.
  86.  
  87.                        =HCOS (hyperbolic cosine)
  88.  
  89. c#=HCOS(a[#])
  90.  
  91. HCOS calculates the hyperbolic cosine of angle a.
  92.  
  93.                       =HTAN (hyperbolic tangent)
  94.  
  95. t#=HTAN(a[#])
  96.  
  97. HTAN returns the hyperbolic tangent of the angle a.
  98.  
  99. Standard mathematical functions
  100.  
  101.                            =LOG (logarithm)
  102.  
  103. r#=LOG(v[#])
  104.  
  105. LOG returns the logarithm in base 10 (log 10) of the expression in v#.
  106.  
  107.                       =EXP (exponential function)
  108.  
  109. r#=EXP(e#)
  110.  
  111. Calculates the exponential of e#. Example:
  112.  
  113.         Print Exp(1)
  114. ( result : 2.71828 )
  115.  
  116.                         =LN (natural logarithm)
  117.  
  118. r#=LN(l#)
  119.  
  120. LN computes the natural of naperian logarithm of l#.
  121.  
  122.                           =SQR (square root)
  123.  
  124. s#=SQR(v[#])
  125.  
  126. SQR calculates the square root of a number.
  127.  
  128.  
  129.  
  130. r=ABS(v[#])
  131.  
  132. ABS returns the absolute value of v, taking no account of its sign.
  133.  
  134.           =INT (convert floating point number to an integer)
  135.  
  136. i=INT(v#)
  137.  
  138. INT rounds a floating point number in v down to the nearest whole
  139. integer.
  140.  
  141.                    =SGN (find the sign of a number)
  142.  
  143. s=SGN(v[#])
  144.  
  145. SGN returns a value of representing the sign of a number. There are
  146. three possibilities.
  147.  
  148.         -1, if v is negative
  149.          0, if v is zero
  150.          1, if v is positive
  151.  
  152. Creating random sequences
  153.  
  154.                     =RND (random number generation)
  155.  
  156. RND generates a random integer between 0 and n inclusive. But if n is
  157. less than zero, RND will return the last value it produced. This can be
  158. very useful when debugging one of your programs.
  159.  
  160.               RANDOMIZE (set the seed of a random number)
  161.  
  162. RANDOMIZE seed
  163.  
  164. In practice, the numbers produced by the RND function are not really
  165. random. They're computed internally using a complex mathematical
  166. formula. The starting point for this calculation is taken from a number
  167. known as the "seed". This seed is set to a standard value whenever you
  168. load AMOS Basic into the computer. So the sequence of numbers generated
  169. by RND will be exactly the same every time you run your game!
  170.  
  171.   The RANDOMIZE command allows you to set the seed value directly, so
  172. that the numbers would really look like random every time.
  173.  
  174.   "seed" can be any value you wish. In order to generate a true random
  175. numbers, you need some way of varying the seed from game to game. This
  176. can be achieved using the TIMER instruction:
  177.  
  178.         Randomize Timer
  179.  
  180. TIMER is a Basic function which returns the amount of time which has
  181. elapsed since your Amiga was switched on in the current session. All
  182. timings are measured in units of a 50th of a second.
  183.  
  184. Manipulating numbers
  185.  
  186.                  =MAX (get the maximum of two values)
  187.  
  188. r=MAX(x,y)
  189. r#=MAX(x#,y#)
  190. r$=MAX(x$,y$)    MAX compares two expressions and returns the largest.
  191.                  These expressions can be composed of numbers or
  192. strings of characters, providing you don't try to mix different types
  193. of expressions in one instruction.
  194.  
  195.         Print Max(10,4)
  196. ( result : 10 )
  197.  
  198.                 =MIN (return the minimum of two values)
  199.  
  200. r=MIN(x,y)
  201. r#=MIN(x#,y#)
  202. r$=MIN(x$,y$)    This works the same way the =MAX does, except returns
  203.                  the minimum value of compared numbers/strings.
  204.  
  205.                SWAP (swap the contents of two variables)
  206.  
  207. SWAP x,y
  208. SWAP x#,y#
  209. SWAP x$,y$       Swaps the data between any two variables of the same
  210.                  type.
  211.  
  212.              FIX (set precision of floating point output)
  213.  
  214. FIX(n)
  215.  
  216. Changes the way your floating point numbers will be displayed on the
  217. screen or printer. There are four possibilities.
  218.  
  219. If 0<n<16 then n denotes the number of figures to be output after
  220.           the decimal point.
  221. If n> 16  the printout will be proportional and any trailing zeros will
  222.           be removed.
  223. If n<0    Then all floating point numbers will be displayed in
  224.           exponential format, and the absolute value of n will
  225.           determine the number of digits after the decimal point.
  226.  
  227. If n=16   then the format will be returned to normal
  228.  
  229.         Fix(-4) : Print PI#
  230.  
  231.                 DEF FN (create a user-defined function)
  232.  
  233. DEF FN name [(list)]=expression
  234.  
  235. The DEF FN command lets you create your own user-defined functions
  236. within an AMOS Basic program. These can be used to compute commonly
  237. needed values quickly and easily.
  238.  
  239.   "nane" is the name of the function you wish to define. "list" is a
  240. set of variables separated by commas. Only the type of these variables
  241. is significant. When you call your function, any variables you enter
  242. with, will be automatically subsituted in the appropriate positions.
  243.  
  244.   "expression" can include any of the standard AMOS functions you wish.
  245. Like all Basic expressions, it's limited just to a single line of prog.
  246.  
  247.                   FN (call a user-defined function)
  248.  
  249. FN name [(variable list)]
  250.  
  251. FN executes a function defined using DEF FN. Example:
  252.  
  253.         Def Fn Asin(X)=90-Acos(X)
  254.         Degree
  255.         Print Fn Asin(0.5)
  256.